﻿var textbox = (function () {
    function cinit(t) {
        if (t.id == "")
            t.id = webjs.newid();
        var tdiv = '<div id="' + t.id + '" class="m-item" style="border-bottom:1px solid #eee">';
        var box = "";
        var but = "";
        if (t.buttonText != "") {
            but = '<a href="javascript:void(0)"  class="easyui-linkbutton" id="link_' + t.field + '" name="' + t.field + '" style="height: 28px; right: 0px;">' + t.buttonText + '</a>';
            box = tdiv + '<div class="m-label">' + t.title + '</div>' + '<div><input class="textbox123" id="' + t.field + '" name="' + t.field + '"  style="width:48%;height:28px;font-size: 16px;line-height: 28px;" ' + t.disabled + '>' + but + '</div></div>';
        }
        else {
            box = tdiv + '<div class="m-label">' + t.title + '</div>' + '<div><input class="textbox123" id="' + t.field + '" name="' + t.field + '"  style="width:60%;height:28px;font-size: 16px;line-height: 28px;" ' + t.disabled + '>' + but + '</div></div>';
        }
        if (t.applyTo != null) {
            $("#" + t.applyTo).append(box);
            if (t.buttonText != "") {
                $("#" + t.id + " #link_" + t.field).linkbutton({
                    onClick: function () {
                        t.onClick();
                    }
                });
            }
            $("#" + t.id + " #" + t.field).bind("change", function (nv) {
                var n = $(this).attr("id");
                var vvv = $(this).val();
                t.onChange(n, vvv);
            });
        };
        return box;
    }
    return {
        datasource: null,
        parent: null,
        id: "",
        field: "",
        type: "",
        title: "",
        disabled: "",
        buttonText: "",
        applyTo: null,
        init: function () {
            return cinit(this);
        },
        onClick: function () {
            this.parent.onTextClick(this.field);
        },
        onChange: function (name, text) {
            this.parent.onChange(name, text, null);
        },
        val: function (v, t) {
            var box = $("#" + this.id + " #" + this.field);
            if (v == undefined) {
                if (this.value)
                    return this.value;
                return box.val();
            }
            if (t != undefined) {
                box.val(t);
                this.value = v;
                return;
            }
            if (this.item) {
                if (this.item.comvtp && this.item.comvtp.isvtp) {
                    for (var i in this.item.comvtp.items) {
                        var com = this.item.comvtp.items[i];
                        if (com.Value == v) {
                            box.val(com.Text);
                            this.value = v;
                            break;
                        }
                    }
                }
            }
            box.val(v);
        },
        getText: function () {
            return $("#" + this.id + " #" + this.field).val();
        },
        disable: function (de) {
            if (!de)
                $("#" + this.id + " #" + this.field).attr("disabled", true);
            else
                $("#" + this.id + " #" + this.field).attr("disabled", false);
        },
        clear: function () {
            this.value = null;
            $("#" + this.id + " #" + this.field).val("");
        },
        focus: function () {
            $("#" + this.id + " #" + this.field).focus();
        },
        getdis: function () {
            return $("#" + this.id + " #" + this.field).attr("disabled");
        },
        test: function () {
            var fdata = this.item.foreign;
            var selecttype = fdata.foreignobject;
        },
        isvalid: function ()
        {

        }
    }
});